home *** CD-ROM | disk | FTP | other *** search
/ Sprite 1984 - 1993 / Sprite 1984 - 1993.iso / src / machserver / 1.098 / Include / fsutil.h < prev    next >
C/C++ Source or Header  |  1991-05-30  |  10KB  |  257 lines

  1. /*
  2.  * fsutil.h --
  3.  *
  4.  *    Declarations of utility routines used by all the file system modules.
  5.  *    This file defines handle types and some sub-structures
  6.  *    that are embedded in various types of handles.  A
  7.  *    "handle" is a data structure that corresponds one-for-one
  8.  *    with a file system object, i.e. a particular file, a device,
  9.  *    a pipe, or a pseudo-device.  A handle is not always one-for-one
  10.  *    with a file system name.  Devices can have more than one name,
  11.  *    and pseudo-devices have many handles associated with one name.
  12.  *    Each handle is identfied by a unique Fs_FileID, and has a standard
  13.  *    header for manipulation by generic routines.
  14.  *
  15.  * Copyright 1989 Regents of the University of California
  16.  * Permission to use, copy, modify, and distribute this
  17.  * software and its documentation for any purpose and without
  18.  * fee is hereby granted, provided that the above copyright
  19.  * notice appear in all copies.  The University of California
  20.  * makes no representations about the suitability of this
  21.  * software for any purpose.  It is provided "as is" without
  22.  * express or implied warranty.
  23.  *
  24.  * $Header: /sprite/src/kernel/fsutil/RCS/fsutil.h,v 9.14 91/05/30 15:02:46 kupfer Exp $ SPRITE (Berkeley)
  25.  */
  26.  
  27. #ifndef _FSUTIL
  28. #define _FSUTIL
  29.  
  30. #include <stdlib.h>
  31.  
  32. #ifdef KERNEL
  33. #include <fs.h>
  34. #include <fsconsist.h>
  35. #include <hash.h>
  36. #include <proc.h>
  37. #include <vm.h>
  38. #include <rpc.h>
  39. #include <timer.h>
  40. #else
  41. #include <kernel/fs.h>
  42. #include <kernel/fsconsist.h>
  43. #include <kernel/hash.h>
  44. #include <kernel/proc.h>
  45. #include <kernel/vm.h>
  46. #include <kernel/rpc.h>
  47. #include <kernel/timer.h>
  48. #endif
  49. /* constants */
  50. /*
  51.  * Define the types of files that we care about in the kernel, for such
  52.  * things as statistics gathering, write-through policy, etc.  There is not
  53.  * necessarily a one-to-one mapping between these and the types defined
  54.  * in user/fs.h as FS_USER_TYPE_*; for example, FS_USER_TYPE_BINARY and
  55.  * FS_USER_TYPE_OBJECT were mapped into FSUTIL_FILE_TYPE_DERIVED before they
  56.  * were separated into two categories.  It would be possible to flag other
  57.  * derived files (text formatting output, for example) to be in the DERIVED
  58.  * category as well.  
  59.  */
  60. #define FSUTIL_FILE_TYPE_TMP 0
  61. #define FSUTIL_FILE_TYPE_SWAP 1
  62. #define FSUTIL_FILE_TYPE_DERIVED 2
  63. #define FSUTIL_FILE_TYPE_BINARY 3
  64. #define FSUTIL_FILE_TYPE_OTHER 4
  65.  
  66. /*
  67.  * How often to try rewriting a file.
  68.  */
  69. #define    FSUTIL_WRITE_RETRY_INTERVAL    30
  70.  
  71. /* data structures */
  72.  
  73. /*
  74.  * Files or devices with remote I/O servers need to keep some recovery
  75.  * state to handle recovery after their server reboots.
  76.  */
  77.  
  78. typedef struct Fsutil_RecoveryInfo {
  79.     Sync_Lock        lock;        /* This struct is monitored */
  80.     Sync_Condition    reopenComplete;    /* Notified when the handle has been
  81.                      * re-opened at the I/O server */
  82.     int            flags;        /* defined in fsRecovery.c */
  83.     ReturnStatus    status;        /* Recovery status */
  84.     Fsio_UseCounts        use;        /* Client's copy of use state */
  85. } Fsutil_RecoveryInfo;
  86.  
  87. /*
  88.  * Statistics for testing recovery.
  89.  */
  90. typedef    struct    Fsutil_FsRecovNamedStats {
  91.     Fs_FileID        fileID;            /* Unique id for object. */
  92.     Boolean        streamHandle;        /* Is this a stream handle? */
  93.     int            mode;            /* Mode of stream. */
  94.     int            refCount;        /* Ref count on IO handle. */
  95.     int            streamRefCount;        /* Ref count on stream. */
  96.     int            numBlocks;        /* Number of blocks in cache. */
  97.     int            numDirtyBlocks;        /* Number dirty cache blocks. */
  98.     char        name[50];        /* Name of object. */
  99. } Fsutil_FsRecovNamedStats;
  100.  
  101.  
  102. extern Boolean fsconsist_Debug;
  103. /*
  104.  * Whether or not to flush the cache at regular intervals.
  105.  */
  106.  
  107. extern Boolean fsutil_ShouldSyncDisks;
  108.  
  109. extern    int    fsutil_NumRecovering;
  110.  
  111. /* procedures */
  112. /*
  113.  * Fsutil_StringNCopy
  114.  *
  115.  *    Copy the null terminated string in srcStr to destStr and return the
  116.  *    actual length copied in *strLengthPtr.  At most numBytes will be
  117.  *    copied if the string is not null-terminated.
  118.  */
  119.  
  120. #define    Fsutil_StringNCopy(numBytes, srcStr, destStr, strLengthPtr) \
  121.     Proc_StringNCopy(numBytes, srcStr, destStr, strLengthPtr)
  122.  
  123. /*
  124.  * Macros to handle type casting when dealing with handles.
  125.  */
  126. #define Fsutil_HandleFetchType(type, fileIDPtr) \
  127.     (type *)Fsutil_HandleFetch(fileIDPtr)
  128.  
  129. #define Fsutil_HandleDupType(type, handlePtr) \
  130.     (type *)Fsutil_HandleDup((Fs_HandleHeader *)handlePtr)
  131.  
  132. #define Fsutil_HandleLock(handlePtr) \
  133.     Fsutil_HandleLockHdr((Fs_HandleHeader *)handlePtr)
  134.  
  135. #define Fsutil_HandleUnlock(handlePtr) \
  136.     (void)Fsutil_HandleUnlockHdr((Fs_HandleHeader *)handlePtr)
  137.  
  138. #define Fsutil_HandleRelease(handlePtr, locked) \
  139.     Fsutil_HandleReleaseHdr((Fs_HandleHeader *)handlePtr, locked)
  140.  
  141. #define Fsutil_HandleRemove(handlePtr) \
  142.     Fsutil_HandleRemoveHdr((Fs_HandleHeader *)handlePtr)
  143.  
  144. #define Fsutil_HandleName(handlePtr) \
  145.     ((((Fs_HandleHeader *)handlePtr) == (Fs_HandleHeader *)NIL) ? \
  146.         "(no handle)": \
  147.       ((((Fs_HandleHeader *)handlePtr)->name == (char *)NIL) ? "(no name)" : \
  148.     ((Fs_HandleHeader *)handlePtr)->name) )
  149.  
  150. #define    Fsutil_TimeInSeconds()    (Timer_GetUniversalTimeInSeconds())
  151.  
  152. #define mnew(type)    (type *)malloc(sizeof(type))
  153.  
  154. #ifdef SOSP91
  155. /*
  156.  * We are borrowing a couple of bits from the handle to record the read/write
  157.  * status of the stream.  Each stream has a handle so we can get away with
  158.  * this.
  159.  */
  160.  
  161. #define FSUTIL_RW_FLAGS     0x300
  162. #define FSUTIL_RW_READ        0x100
  163. #define FSUTIL_RW_WRITE        0x200
  164.  
  165. #endif
  166.  
  167. extern void Fsutil_RecoveryInit _ARGS_((Fsutil_RecoveryInfo *recovPtr));
  168. extern void Fsutil_RecoverySyncLockCleanup _ARGS_((
  169.         Fsutil_RecoveryInfo *recovPtr));
  170. extern void Fsutil_WantRecovery _ARGS_((Fs_HandleHeader *hdrPtr));
  171. extern void Fsutil_AttemptRecovery _ARGS_((ClientData data, 
  172.         Proc_CallInfo *callInfoPtr));
  173. extern ReturnStatus Fsutil_WaitForRecovery _ARGS_((Fs_HandleHeader *hdrPtr, 
  174.         ReturnStatus rpcStatus));
  175. extern Boolean Fsutil_RecoveryNeeded _ARGS_((Fsutil_RecoveryInfo *recovPtr));
  176. extern void Fsutil_Reopen _ARGS_((int serverID, ClientData clientData));
  177. extern Boolean Fsutil_RemoteHandleScavenge _ARGS_((Fs_HandleHeader *hdrPtr));
  178. extern void Fsutil_ClientCrashed _ARGS_((int spriteID, ClientData clientData));
  179. extern void Fsutil_ClientCrashed _ARGS_((int spriteID, ClientData clientData));
  180. extern void Fsutil_RemoveClient _ARGS_((int clientID));
  181.  
  182.  
  183. /*
  184.  * Wait list routines.  Waiting lists for various conditions are kept
  185.  * hanging of I/O handles.
  186.  */
  187. extern void Fsutil_WaitListInsert _ARGS_((List_Links *list, 
  188.         Sync_RemoteWaiter *waitPtr));
  189. extern void Fsutil_WaitListNotify _ARGS_((List_Links *list));
  190. extern void Fsutil_FastWaitListInsert _ARGS_((List_Links *list, 
  191.         Sync_RemoteWaiter *waitPtr));
  192. extern void Fsutil_FastWaitListNotify _ARGS_((List_Links *list));
  193. extern void Fsutil_WaitListDelete _ARGS_((List_Links *list));
  194. extern void Fsutil_WaitListRemove _ARGS_((List_Links *list, 
  195.         Sync_RemoteWaiter *waitPtr));
  196.  
  197. /*
  198.  * File handle routines.
  199.  */
  200. extern void Fsutil_HandleInit _ARGS_((int fileHashSize));
  201. extern Boolean Fsutil_HandleInstall _ARGS_((Fs_FileID *fileIDPtr, 
  202.     int size, char *name, Boolean cantBlock, Fs_HandleHeader **hdrPtrPtr));
  203. extern Fs_HandleHeader *Fsutil_HandleFetch _ARGS_((Fs_FileID *fileIDPtr));
  204. extern Fs_HandleHeader *Fsutil_HandleFetchNoWait _ARGS_((Fs_FileID *fileIDPtr,
  205.                         Boolean *wouldWaitPtr));
  206. extern Fs_HandleHeader *Fsutil_HandleDup _ARGS_((Fs_HandleHeader *hdrPtr));
  207. extern Fs_HandleHeader *Fsutil_GetNextHandle _ARGS_((Hash_Search *hashSearchPtr));
  208. extern void Fsutil_HandleLockHdr _ARGS_((Fs_HandleHeader *hdrPtr));
  209. extern void Fsutil_HandleIncRefCount _ARGS_((Fs_HandleHeader *hdrPtr,
  210.         int amount));
  211. extern void Fsutil_HandleDecRefCount _ARGS_((Fs_HandleHeader *hdrPtr));
  212. extern void Fsutil_HandleInvalidate _ARGS_((Fs_HandleHeader *hdrPtr));
  213. extern Boolean Fsutil_HandleValid _ARGS_((Fs_HandleHeader *hdrPtr));
  214. extern Boolean Fsutil_HandleUnlockHdr _ARGS_((Fs_HandleHeader *hdrPtr));
  215. extern void Fsutil_HandleReleaseHdr _ARGS_(( Fs_HandleHeader *hdrPtr, 
  216.         Boolean locked));
  217. extern void Fsutil_HandleRemoveHdr _ARGS_((Fs_HandleHeader *hdrPtr));
  218. extern Boolean Fsutil_HandleAttemptRemove _ARGS_((Fs_HandleHeader *hdrPtr));
  219. extern void Fsutil_HandleRemoveInt _ARGS_((Fs_HandleHeader *hdrPtr));
  220. /*
  221.  * Miscellaneous.
  222.  */
  223. extern void Fsutil_FileError _ARGS_((Fs_HandleHeader *hdrPtr, char *string, 
  224.         int status));
  225. extern void Fsutil_PrintStatus _ARGS_((int status));
  226. extern char *Fsutil_FileTypeToString _ARGS_((int type));
  227.  
  228. extern ReturnStatus Fsutil_DomainInfo _ARGS_((Fs_FileID *fileIDPtr, 
  229.         Fs_DomainInfo *domainInfoPtr));
  230.  
  231. extern int Fsutil_HandleDescWriteBack _ARGS_((Boolean shutdown, int domain));
  232. extern void Fsutil_SyncProc _ARGS_((ClientData data, 
  233.         Proc_CallInfo *callInfoPtr));
  234. extern void Fsutil_Sync _ARGS_((unsigned int writeBackTime, Boolean shutdown));
  235. extern void Fsutil_SyncStub _ARGS_((ClientData data));
  236. extern ReturnStatus Fsutil_WaitForHost _ARGS_((Fs_Stream *streamPtr, int flags,
  237.         ReturnStatus rpcStatus));
  238. extern int Fsutil_TraceInit _ARGS_((void));
  239. extern int Fsutil_PrintTraceRecord _ARGS_((ClientData clientData, int event,
  240.         Boolean printHeaderFlag));
  241. extern void Fsutil_PrintTrace _ARGS_((ClientData clientData));
  242. extern ReturnStatus Fsutil_RpcRecovery _ARGS_((ClientData srvToken, 
  243.         int clientID, int command, Rpc_Storage *storagePtr));
  244.  
  245.  
  246. extern void Fsutil_HandleScavengeStub _ARGS_((ClientData data));
  247. extern void Fsutil_HandleScavenge _ARGS_((ClientData data, 
  248.         Proc_CallInfo *callInfoPtr));
  249.  
  250. extern char *Fsutil_GetFileName _ARGS_((Fs_Stream *streamPtr));
  251.  
  252. extern ReturnStatus Fsutil_FsRecovInfo _ARGS_((int length, 
  253.         Fsutil_FsRecovNamedStats *resultPtr, int *lengthNeededPtr));
  254.  
  255. extern int Fsutil_TestForHandles _ARGS_((int serverID));
  256. #endif /* _FSUTIL */
  257.